<template>
  <div class="user_header" style="background-color: red">
    <van-icon name="set" class="user_set" style="margin-top: 5vh" @click="userSet()"/>
    <div class="user_avatar">
      <img :src="avatar" alt="头像" width="55" height="55">
    </div>
    <div>{{nickName}}</div>
  </div>
</template>

<script>
import avatar_default from '@/assets/images/avatar_default.png';
import {ApiService} from "@/axios/apiService";

export default {
  name: 'user-header',

  props: {
    isLogin: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {
      nickName: '昵称',
      avatar: avatar_default,
      background_image: 'https://img.yzcdn.cn/vant/apple-1.jpg'
    };
  },
  methods: {
    userSet() {
      this.$router.push("/user/edit")
    },
    getUserInfo() {
      const api = new ApiService("/user")
      api.getParams({
        userId:api.getCookie("userId")
      }).then(res=> {
        this.nickName = res.data.data.name;
        var header = res.data.data.header;
        if (header!==null) {
          console.log("header"+header)
          this.avatar = header
        }
      })
    },
  },
  mounted() {
    this.getUserInfo()
  }
}
</script>

<style lang="scss" scoped>
.user_header {
  background-repeat: no-repeat;
  background-size: cover;
  height: 130px;
  text-align: center;
  color: #fff;
  padding-top: 30px;
}

.user_set {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 24px;
}
.user_avatar {
  margin-bottom: 10px;
  img {
    border: 0;
    border-radius: 50%;
  }
}
</style>
